﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;

namespace CNVP.JShop.BLL
{
    public class BLLColumn:CNVP_Column
    {
        /// <summary>
        /// 写DropDownList
        /// </summary>
        /// <param name="ddList">下拉控件</param>
        /// <param name="ColumnType">类型:'1'代表友情链接,'2'代表文章,'3'代表产品,'4'代表运费</param>
        public void BuildAllDDList(System.Web.UI.WebControls.DropDownList ddList, int ColumnType)
        {
            var allitems = base.GetAll_CNVP_Column();
            var topitems = base.GetAll_CNVP_Column("Depth=0 and ColumnType=" + ColumnType + " ");
            foreach (var item in topitems)
            {
                ListItem Litem = new ListItem()
                {
                    Value = item.ID.ToString(),
                    Text = item.ColumnName
                };
                ddList.Items.Add(Litem);
                BuildPartDDList(ddList, Litem, item.ID, allitems, 2, ColumnType);

            }
        }

        private void BuildPartDDList(System.Web.UI.WebControls.DropDownList ddList, ListItem currentItem, int currentMenuID, List<Model.CNVP_Column> datasource, Int32 vv, int ColumnType)
        {
            Int32 predll = vv + 2;
            var subMenus = base.GetAll_CNVP_Column(" Depth=" + currentMenuID + " and ColumnType=" + ColumnType + " order by OrderID");
            foreach (var item in subMenus)
            {
                ListItem Litem = new ListItem()
                {
                    Value = item.ID.ToString(),
                    Text = Convert.ToString(item.ColumnName).PadLeft(Convert.ToString(item.ColumnName).Length + vv, (char)0xA0)
                };
                ddList.Items.Add(Litem);
                this.BuildPartDDList(ddList, currentItem, item.ID, datasource, predll, ColumnType);
            }
        }
        
    }
}
